/*
 * Copyright 2020-2023 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zmhhxl.sample3.oauth2.a.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.CurrentSecurityContext;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;

/**
 * @author Steve Riesenberg
 * @since 1.1
 */
@Controller
public class LoginController {

//	@RequestMapping("/login")
//	public String login() {
//		return "login.html";
//	}

	/**
	 * Oauth 2 login page string.
	 *
	 * @param model              the model
	 * @param authentication     the authentication
	 * @param enableCaptchaLogin the enable captcha login
	 * @param csrfToken          the csrf token
	 * @return the string
	 */
	@GetMapping("/login")
	String login(Model model,
					 @CurrentSecurityContext(expression = "authentication") Authentication authentication,
					 @Value("${spring.security.oauth2.server.login.captcha.enabled:true}") boolean enableCaptchaLogin,
					 @RequestAttribute(name = "org.springframework.security.web.csrf.CsrfToken", required = false) CsrfToken csrfToken) {
		if (csrfToken != null) {
			model.addAttribute("_csrfToken", csrfToken);
		}
		return "login";
	}

//	@GetMapping("/login?error")
//	public String loginError() {
//		return "login";
//	}
//
//	@GetMapping("/login?process")
//	public String loginProcess() {
//		return "login";
//	}

}
